<template>
    <view class="assessment-result-container">
        <!-- 评估结果 -->
        <view class="result-section">
            <view class="header">
                <view class="icon" :style="{ backgroundColor: result.color }">
                    <u-icon :name="result.icon" size="40" color="#fff"></u-icon>
                </view>
                <view class="title">{{result.title}}</view>
            </view>
            <view class="score">
                <text class="value">{{result.score}}</text>
                <text class="unit">分</text>
            </view>
            <view class="level" :class="result.level">
                {{result.levelText}}
            </view>
            <view class="description">{{result.description}}</view>
        </view>
        
        <!-- 风险因素 -->
        <view class="factors-section">
            <view class="section-title">主要风险因素</view>
            <view class="factors">
                <view class="factor-item" v-for="(factor, index) in result.factors" :key="index">
                    <view class="factor-header">
                        <text class="number">{{index + 1}}.</text>
                        <text class="name">{{factor.name}}</text>
                        <text class="score">({{factor.score}}分)</text>
                    </view>
                    <view class="suggestion">{{factor.suggestion}}</view>
                </view>
            </view>
        </view>
        
        <!-- 改善建议 -->
        <view class="suggestions-section">
            <view class="section-title">改善建议</view>
            <view class="suggestions">
                <view class="suggestion-item" v-for="(suggestion, index) in result.suggestions" :key="index">
                    <view class="suggestion-header">
                        <text class="number">{{index + 1}}.</text>
                        <text class="title">{{suggestion.title}}</text>
                    </view>
                    <view class="content">{{suggestion.content}}</view>
                </view>
            </view>
        </view>
        
        <!-- 底部按钮 -->
        <view class="bottom-buttons">
            <u-button type="primary" @click="viewHistory">查看历史记录</u-button>
            <u-button type="default" @click="shareResult">分享结果</u-button>
        </view>
    </view>
</template>

<script>
import request from '@/util/request'

export default {
    data() {
        return {
            result: {
                id: 1,
                title: '脑卒中风险评估',
                icon: 'heart',
                color: '#FF6B6B',
                score: 65,
                level: 'medium',
                levelText: '中风险',
                description: '您的脑卒中风险处于中等水平，需要注意改善生活习惯，定期进行健康检查。',
                factors: [
                    {
                        name: '高血压',
                        score: 20,
                        suggestion: '建议定期监测血压，遵医嘱服药，保持低盐饮食。'
                    },
                    {
                        name: '缺乏运动',
                        score: 15,
                        suggestion: '建议每周进行3-5次中等强度运动，每次30分钟以上。'
                    },
                    {
                        name: '吸烟',
                        score: 10,
                        suggestion: '建议戒烟，减少二手烟暴露。'
                    }
                ],
                suggestions: [
                    {
                        title: '饮食建议',
                        content: '保持均衡饮食，多吃蔬菜水果，减少高盐、高脂食物摄入。'
                    },
                    {
                        title: '运动建议',
                        content: '每周进行3-5次中等强度运动，如快走、游泳、骑自行车等。'
                    },
                    {
                        title: '生活习惯',
                        content: '戒烟限酒，保持规律作息，避免熬夜。'
                    },
                    {
                        title: '定期检查',
                        content: '建议每半年进行一次健康检查，监测血压、血糖、血脂等指标。'
                    }
                ]
            }
        }
    },
    methods: {
        async loadResult() {
            try {
                const id = this.$route.query.id
                const res = await request.get(`/api/assessment/result/${id}`)
                if (res.code === 200) {
                    this.result = res.data
                }
            } catch (error) {
                console.log(error)
            }
        },
        
        viewHistory() {
            uni.navigateTo({
                url: '/pages/my/assessment'
            })
        },
        
        shareResult() {
            uni.showShareMenu({
                withShareTicket: true,
                menus: ['shareAppMessage', 'shareTimeline']
            })
        }
    },
    onLoad() {
        this.loadResult()
    }
}
</script>

<style lang="less" scoped>
.assessment-result-container {
    min-height: 100vh;
    background-color: #F8F8F8;
    padding-bottom: 120rpx;
    
    .result-section {
        background-color: #fff;
        padding: 40rpx 30rpx;
        text-align: center;
        
        .header {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 20rpx;
            
            .icon {
                width: 80rpx;
                height: 80rpx;
                border-radius: 40rpx;
                display: flex;
                align-items: center;
                justify-content: center;
                margin-right: 20rpx;
            }
            
            .title {
                font-size: 36rpx;
                font-weight: bold;
                color: #333;
            }
        }
        
        .score {
            margin: 30rpx 0;
            
            .value {
                font-size: 80rpx;
                font-weight: bold;
                color: #333;
            }
            
            .unit {
                font-size: 32rpx;
                color: #666;
                margin-left: 10rpx;
            }
        }
        
        .level {
            display: inline-block;
            padding: 10rpx 30rpx;
            border-radius: 30rpx;
            font-size: 28rpx;
            font-weight: bold;
            margin-bottom: 20rpx;
            
            &.low {
                background-color: #E1F3D8;
                color: #67C23A;
            }
            
            &.medium {
                background-color: #FDF6EC;
                color: #E6A23C;
            }
            
            &.high {
                background-color: #FEF0F0;
                color: #F56C6C;
            }
        }
        
        .description {
            font-size: 28rpx;
            color: #666;
            line-height: 1.6;
        }
    }
    
    .factors-section,
    .suggestions-section {
        background-color: #fff;
        margin-top: 20rpx;
        padding: 30rpx;
        
        .section-title {
            font-size: 32rpx;
            font-weight: bold;
            color: #333;
            margin-bottom: 20rpx;
        }
    }
    
    .factors-section {
        .factors {
            .factor-item {
                margin-bottom: 30rpx;
                
                &:last-child {
                    margin-bottom: 0;
                }
                
                .factor-header {
                    display: flex;
                    align-items: center;
                    margin-bottom: 10rpx;
                    
                    .number {
                        font-size: 28rpx;
                        color: #333;
                        font-weight: bold;
                        margin-right: 10rpx;
                    }
                    
                    .name {
                        flex: 1;
                        font-size: 28rpx;
                        color: #333;
                        font-weight: bold;
                    }
                    
                    .score {
                        font-size: 24rpx;
                        color: #999;
                    }
                }
                
                .suggestion {
                    font-size: 28rpx;
                    color: #666;
                    line-height: 1.6;
                    padding-left: 30rpx;
                }
            }
        }
    }
    
    .suggestions-section {
        .suggestions {
            .suggestion-item {
                margin-bottom: 30rpx;
                
                &:last-child {
                    margin-bottom: 0;
                }
                
                .suggestion-header {
                    display: flex;
                    align-items: center;
                    margin-bottom: 10rpx;
                    
                    .number {
                        font-size: 28rpx;
                        color: #333;
                        font-weight: bold;
                        margin-right: 10rpx;
                    }
                    
                    .title {
                        font-size: 28rpx;
                        color: #333;
                        font-weight: bold;
                    }
                }
                
                .content {
                    font-size: 28rpx;
                    color: #666;
                    line-height: 1.6;
                    padding-left: 30rpx;
                }
            }
        }
    }
    
    .bottom-buttons {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #fff;
        padding: 20rpx 30rpx;
        box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
        display: flex;
        
        .u-button {
            flex: 1;
            margin: 0 10rpx;
        }
    }
}
</style> 